import React, { PureComponent } from 'react';
import VoteMain from './voteMain.jsx';
import VoteFooter from './voteFooter.jsx';
// 类投票器demo
class Vote extends PureComponent {
    state = {
        upNum: 10,
        downNum: 1,
    }
    change = (type) => {
        if (type === 'up') {
            this.setState({
                upNum: this.state.upNum + 1,
            });
        } else {
            this.setState({
                downNum: this.state.downNum + 1,
            });
        }
    }
    render () {
        return (
            <div>
                <p>投票</p>
                <p>总人数：{this.state.upNum + this.state.downNum}</p>
                <p>支持率：{(this.state.upNum / (this.state.upNum + this.state.downNum) * 100).toFixed(2)}%</p>
                <VoteMain upNum={this.state.upNum} downNum={this.state.downNum} />
                <VoteFooter change={this.change} />
            </div>
        );
    }
}

export default Vote;